import React from 'react';
import styles from '@/assets/css/login.module.css';


export default () =>
{
    // 创建表单的控制实例
    const [form] = React.UI.Form.useForm()

    //表单提交的方法
    const LoginFinish = async (values: any) => 
    {
        let result = await React.request.post('/business/UserLogin', values)
        
        if(result.code == 0)
        {
            React.toast(result.msg)
            return false
        }

        //保存登录信息
        React.cookies.save('business', result.data, {path: '/'})
        React.business = result.data

        React.toast(result.msg, () => {
            React.navigate(result.url)
        })
    }

    return (
        <>
            <div className={styles.headers}>
                <div className={styles.userinfo}>
                    <div className={styles.avatar}></div>
                </div>
                <div className={styles.corrugated}>
                    <div className={`${styles.wave_top} ${styles.wave_item}`}></div>
                    <div className={`${styles.wave_middle} ${styles.wave_item}`}></div>
                </div>
            </div>

            <div className={styles.login}>
                <React.UI.Form
                    layout='horizontal'
                    mode='card'
                    form={form}
                    onFinish={LoginFinish}
                    footer={
                        <div style={{ margin: '16px 16px 0' }}>
                            <React.UI.Button shape='rounded' type='submit' color='warning' block>
                                登陆注册
                            </React.UI.Button>
                        </div>
                    }
                >
                    <React.UI.Form.Item
                        name='mobile'
                        label="手机号码"
                        initialValue="18888888888"
                        rules={[
                            {required: true, message: '请填写手机号码'},
                            {pattern: /^1[356789]\d{9}$/, message: '请输入正确格式的手机号码'}
                        ]}
                    >
                        <React.UI.Input placeholder="请输入手机号码" />
                    </React.UI.Form.Item>

                    <React.UI.Form.Item
                        initialValue="123123"
                        rules={[{required: true, message: '请输入密码'}]}
                        name="password"
                        label="密码"
                    >
                        <React.UI.Input placeholder="请输入密码" type="password" />
                    </React.UI.Form.Item>
                </React.UI.Form>
            </div>
        </>
    )
}